package com.niiwoo.civet.trade.service.local.notify.impl;

import com.niiwoo.civet.trade.dao.entity.Project;
import com.niiwoo.civet.trade.enums.NotifyTypeEnum;
import com.niiwoo.civet.user.dto.request.JPushExtDTO;
import com.niiwoo.civet.user.dto.request.UserLetterRequestDTO;
import com.niiwoo.civet.user.enums.JPushEnum;
import com.niiwoo.civet.user.enums.MessageTemplateKeyEnum;
import com.niiwoo.civet.user.enums.SMSTemplateKeyEnum;
import com.niiwoo.civet.user.enums.UserLetterTypeEnum;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.springframework.stereotype.Component;

@Component
public class ProjectFlowMiscarryInvestOvertimeNotifier extends AbstractBorrowNotifier<Project> {

    // 借款通过审核后，超过7天投资期限未满标流标
    // JS011 借款人
    // "通知 + 极光推送：借款项目流标通知 / 您好，您的借款项目【项目名称】已流标。原因为：规定时间内投资未满流标。
    // 短信：您好，您的借款项目【项目名称】已流标。原因为：规定时间内投资未满流标。"
    @Override
    protected UserLetterRequestDTO getUserLetterRequestDTO(UserNotifyInfo info) {
        BorrowUserNotifyInfo p = (BorrowUserNotifyInfo) info;
        UserLetterRequestDTO letterRequest = new UserLetterRequestDTO();
        // 通知
        List<Object> letterParams = Arrays.asList(p.getProjectId(), p.getProjectTitle());
        letterRequest.setLetterTemplateEnum(MessageTemplateKeyEnum.LetterTemplateKeyEnum.PROJECT_FLOW_MISCARRY_INVEST_OVERTIME);
        letterRequest.setLetterTemplateParamList(letterParams);
        // 极光推送
        List<Object> pushParams = Collections.singletonList(p.getProjectTitle());
        letterRequest.setJpushTemplateKeyEnum(MessageTemplateKeyEnum.JPushTemplateKeyEnum.PROJECT_FLOW_MISCARRY_INVEST_OVERTIME);
        letterRequest.setJpushTemplateParamList(pushParams);
        letterRequest.setToUserId(p.getUserId());
        letterRequest.setProjectId(p.getProjectId());
        letterRequest.setUserLetterTypeEnum(UserLetterTypeEnum.LETTER_AND_JPUSH);
        JPushExtDTO jPushExtDTO = new JPushExtDTO();
        jPushExtDTO.setRedirectPageEnum(JPushEnum.RedirectPageEnum.NOTICE_LIST_PAGE);
        letterRequest.setJPushExt(jPushExtDTO);
        return letterRequest;
    }

    @Override
    protected SMSTemplateKeyEnum getSMSTemplateKey() {
        return SMSTemplateKeyEnum.PROJECT_FLOW_MISCARRY_INVEST_OVERTIME;
    }

    @Override
    protected NotifyTypeEnum getType() {
        return NotifyTypeEnum.JS011;
    }

}
